home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / winlib.lzh / WINLIB / SCRAP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-23  |  2.6 KB  |  145 lines

  1. /********************************************************************
  2.  *                                                                    *
  3.  *    Scrap directory routines                                        *
  4.  *    by Christian Grunenberg                                            *
  5.  *                                                                    *
  6.  *    Copied from E_GEM 1.3                                            *
  7.  *    Copyright (C) 1993, Christian Grunenberg                        *
  8.  *                                                                    *
  9.  ********************************************************************/
  10.  
  11. #include <string.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <tos.h>
  15. #include "winlib.h"
  16.  
  17. LOCAL char *strmfp(char *dest,char *path,char *file)
  18. {
  19.     register char *last;
  20.     register int len;
  21.  
  22.     if (path)
  23.         strcpy(dest,path);
  24.  
  25.     if ((len = (int) strlen(dest))>0)
  26.     {
  27.         last = dest + len - 1;
  28.         if (*last!='\\')
  29.         {
  30.             *++last = '\\';
  31.             *++last = '\0';
  32.         }
  33.     }
  34.  
  35.     return(strcat(dest,file));
  36. }
  37.  
  38. GLOBAL int scrp_init(char *path)
  39. {
  40.     register char scrap[256];
  41.     register long handle,len;
  42.  
  43.     scrp_read(scrap);
  44.     if (scrap[0]=='\0')
  45.     {
  46.         if (path)
  47.             strcpy(scrap,path);
  48.         else if ((path = getenv("CLIPBRD"))!=NULL || (path = getenv("SCRAPDIR"))!=NULL)
  49.             strcpy(scrap,path);
  50.         else
  51.         {
  52.             register long ssp;
  53.  
  54.             strcpy(scrap,"X:\\CLIPBRD");
  55.             ssp = Super(NULL);
  56.             *scrap = (char) (*((int *) 0x446)+65);
  57.             Super((void *) ssp);
  58.         }
  59.     }
  60.  
  61.     if ((len = strlen(scrap))>0)
  62.     {
  63.         len--;
  64.         if (scrap[len]=='\\')
  65.             scrap[len]='\0';
  66.     
  67.         handle = Dcreate(scrap);
  68.         if (handle>=0 || handle==-36)
  69.         {
  70.             scrp_write(strcat(scrap,"\\"));
  71.             return(TRUE);
  72.         }
  73.     }
  74.  
  75.     scrp_write("");
  76.     return(FALSE);
  77. }
  78.  
  79. GLOBAL void scrp_clear()
  80. {
  81.     register char scrap[256];
  82.     
  83.     scrp_read(scrap);
  84.     if (scrap[0]!='\0')
  85.     {
  86.         register DTA *dta=Fgetdta();
  87.         register char xpath[256],xname[256];
  88.  
  89.         strmfp(xpath,scrap,"SCRAP.*");
  90.         if (!Fsfirst(xpath,0))
  91.             do
  92.             {
  93.                 strmfp(xname,scrap,dta->d_fname);
  94.                 remove(xname);
  95.             }
  96.             while (!Fsnext());
  97.     }
  98. }
  99.  
  100. GLOBAL int scrp_length()
  101. {
  102.     register char scrap[256];
  103.     
  104.     scrp_read(scrap);
  105.     if (scrap[0]!='\0')
  106.     {
  107.         register DTA *dta=Fgetdta();
  108.         register char xpath[256];
  109.  
  110.         strmfp(xpath,scrap,"SCRAP.*");
  111.         if (!Fsfirst(xpath,0))
  112.         {
  113.             register long length = 0;
  114.             do
  115.                 length += dta->d_length;
  116.             while (!Fsnext());
  117.             return ((int) ((length+512)>>10));
  118.         }
  119.     }
  120.  
  121.     return (0);
  122. }
  123.  
  124. GLOBAL int scrp_find(char *extension,char *filename)
  125. {
  126.     register char scrap[256];
  127.     
  128.     scrp_read(scrap);
  129.     if (scrap[0]!='\0')
  130.     {
  131.         register DTA  *dta=Fgetdta();
  132.         register char xpath[256];
  133.         register int  c = 0;
  134.  
  135.         strcat(strmfp(xpath,scrap,"SCRAP."),extension);
  136.         if(!Fsfirst(xpath,0))
  137.         {
  138.             c++;
  139.             strmfp(filename,scrap,dta->d_fname);
  140.             while (!Fsnext()) c++;
  141.             return (c);
  142.         }
  143.     }
  144.     return (0);
  145. }